
// TestWorld.cpp

#include "TestWorld.h"


TestWorld::TestWorld()
{
	m_hWnd = NULL;
	m_hInstance = NULL;
	m_D3D = NULL;
	m_pDevice = NULL;
	m_Cam = NULL;
	m_Input = NULL;
	m_Spr1 = NULL;
	m_bInit = FALSE;
}

TestWorld::~TestWorld()
{
}


int TestWorld::Create( HWND hWnd, HINSTANCE hInst )
{
	if ( m_bInit )
	{
		return -1;
	}

	m_hWnd = hWnd;
	m_hInstance = hInst;

	// d3d
	m_D3D = new kkDirect3D;
	m_D3D->Create( m_hWnd, m_hInstance, CSWIDTH, CSHEIGHT, FALSE );
	m_D3D->GetDevice( &m_pDevice );
	m_D3D->SetDefaultLight( 0 );
	m_D3D->UseDefaultLight( 0 );
	m_D3D->LightEnable( 0, TRUE );
	m_D3D->SetDefaultMaterial();
	m_D3D->UseDefaultMaterial();

	// cam
	m_Cam = new kkCamera;
	m_Cam->Create( m_pDevice, KKCAMERATYPE_TARGET );
	m_Cam->SetProjection( D3DX_PI * 0.5f, (FLOAT)CSWIDTH / (FLOAT)CSHEIGHT, 1.0f, 1000.0f );
	m_Cam->UpdateProjection();
	m_Cam->SetView( &D3DXVECTOR3( 10.0f, 10.0f, -10.0f ), &VEC_ORIGIN, &VEC_UP );
	m_Cam->UpdateView();

	// input
	m_Input = new kkDirectInput;
	m_Input->Create( m_hWnd, m_hInstance );


	// sprite
	m_Spr1 = new kkUISprite;
	//m_Spr1->Create( m_pDevice, _T( "imgs/001.jpg" ) );
	m_Spr1->Scaling( 0.1f, 0.1f );

	m_bInit = TRUE;

	return 0;
}

void TestWorld::Release()
{
	if ( !m_bInit )
	{
		return;
	}

	KKRELDEL( m_Spr1 );
	KKRELDEL( m_Input );
	KKRELDEL( m_Cam );
	KKRELDEL( m_D3D );

	TestWorld();
}


int TestWorld::Update()
{
	if ( !m_bInit )
	{
		return -1;
	}

	return 0;
}

int TestWorld::Render()
{
	if ( !m_bInit )
	{
		return -1;
	}

	m_D3D->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0 );
	m_D3D->BeginScene();

	m_D3D->EndScene();

	m_D3D->Present();

	return 0;
}